package com.optimus.db.dao.impl;

import com.optimus.common.cvo.VerificadorVOList;
import com.optimus.common.util.ApplicationException;
import com.optimus.common.vo.VerificadorVO;
import com.optimus.db.QueryFactory;
import com.optimus.db.dao.VerificadorDAO;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.SQLQuery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author victor
 */
public class VerificadorDAOImpl extends BaseDAO implements VerificadorDAO {

    private static  Logger logger = LoggerFactory.getLogger(VerificadorDAOImpl.class);

    public VerificadorDAOImpl(){
        super();
    }

    public VerificadorVOList listar(VerificadorVO productoVO) throws ApplicationException {
        Object[] logParams = new Object[2];
        VerificadorVOList result = new VerificadorVOList();
        result.setLista(new ArrayList<VerificadorVO>());
        result.setTicket(productoVO.getTicket());
        VerificadorVO item = null;
        Long tk = result.getTicket();
        try {
            String queryStr=QueryFactory.instance().query("verificador_listar", productoVO.getTicket());
            logParams[0] = queryStr;
            checkSession();
            session.beginTransaction();
            SQLQuery query = session.createSQLQuery(queryStr);            
            Object objList = query.list();
            Object[] itemObj = null;
            for (Object obj : (List) objList) {
                itemObj = (Object[]) obj;
                item = new VerificadorVO();
                item.setIdVerificador(getInteger(itemObj[0], null, tk));
                item.setT(getString(itemObj[1], null, tk));
                item.setEstadoRegistro(getString(itemObj[2], null, tk));
                item.setFechaCreacion(getDate(itemObj[3], null, tk));
                item.setIdUsuario(getString(itemObj[4], null, tk));
                item.setNombre(getString(itemObj[5], null, tk));
                result.getLista().add(item);
            }
            session.getTransaction().commit();
        } catch (Exception e) {
            throw new ApplicationException("MDB0000", e);
        } finally {
            logger.info("sql={} ", logParams);
        }
        return result;
    }

}
